<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
    <title></title>
    <link href="<s:url value='/common/lib/ligerUI/skins/Aqua/css/ligerui-all.css'/>" rel="stylesheet" type="text/css" />
    <link href="<s:url value='/common/lib/ligerUI/skins/ligerui-icons.css'/>" rel="stylesheet" type="text/css" />
    <script src="<s:url value='/common/lib/jquery/jquery-1.3.2.min.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/core/base.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerTree.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerDialog.js'/>" type="text/javascript"></script>
    <script src="<s:url value='/common/dealer.js'/>" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("#paramBox").hide();
            $("#downloadBox").hide();
            var tree = $("#tree1").ligerTree({
				single:true,
                nodeDraggable: false,
                checkbox:false,
                onSelect:function(node) {
                	if(node.data.netCode) {
	                	$("#paramBox").show();
	                	$("#stroragePath").hide();
	                	$("#stroragePathLabel").hide();
	                	$("#downloadBox").hide();
	                	$("#stroragePath option").remove();
	                	$("#dealerLabel").text("您选择了经销商：" + node.data.text);
	                	var dc = node.data.netCode;
	                	var dcName = node.data.text;
	                	downlaod(dc, dcName);
                	}
                },
                data: getDealers()
            });
            tree.collapseAll();
        });
        
        function downlaod(dc, dcName) {
        	$("#dc").val(dc);
        	$("#dcName").val(dcName);
        	$.post("<s:url value='/record/getStroragePaths.action'/>",{dealerCode : dc}, function(data) {
        		var datas = data.split(":");
        		if(datas[0] == 0) {
        			$("#stroragePath").show();
        			$("#stroragePathLabel").show();
        			$("#stroragePath").prepend("<option value='0'>请选择...</option>");
        			var dirs = datas[1].split(",");
        			for(var i = 0; i < dirs.length; i++) {
        				var dir = dirs[i].replace(/\n/g, "").replace(/\r/g, "");
        				$("#stroragePath").append("<option value='" + dir + "'>" + dir + "</option>");
        			}
        		} else {
        			$.ligerDialog.alert('该经销商尚未上传数据!', '提示', 'none');
        		}
        	});
        }
        
        function handleChange() {
        	var val = $("#stroragePath").val();
			if(val != 0) {
				$("#stroragePath").attr("disabled","disabled");
				$("#downloadBox").show();
				$("#downloadfile").hide();
				$("#prepDownloadFile").show();
				var dc = $("#dc").val();
				var dcName = $("#dcName").val();
				$.post("<s:url value='/record/prepDownloadFile.action'/>",{dealerCode:dc,timeStamp:val}, function(data) {
					if(data == 0) {
						$("#prepDownloadFile").hide();
						$("#downloadfile").attr("href","<s:url value='/zip-temp/'/>" + dc + "-" + dcName + "-" + val + ".zip");
						$("#downloadfile").text(dc + "-" + dcName + "-" + val + ".zip");
						$("#downloadfile").show();
						$("#stroragePath").attr("disabled","");
					}
				});
			}
        }
    </script>
</head>
<body style="padding:10px">
	<input type="hidden" id="dc"/>
	<input type="hidden" id="dcName"/>
	<h3>生成明细表</h3>
	<div style="width:1680px;">
	<div style="width: 300px; height: 800px; margin-left: 5px; margin-right: 1px; float:left; border: 1px solid #A3C0E8;">
		<h4>请先选择经销商</h4>
		<ul id="tree1"></ul>
	</div>

	<div style="width:80%; height:800px;border:1px solid #A3C0E8; float: right">
		<div id="paramBox" style="margin: 5px;">
			<label id="dealerLabel"></label>
			<br/>
			<label id="stroragePathLabel">请选择原始数据上传日期：</label><select id="stroragePath" onchange="handleChange()"></select>
		</div>
		
		<div id="downloadBox" style="width:100%;">
			<label id="prepDownloadFile">正在压缩数据，请稍后...</label>
			<a id="downloadfile" target="_blank" title="请点击鼠标右键，选择链接另存为"></a>
		</div>
	</div>
	</div>
</body>
</html>